<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
	<link rel="stylesheet" href="">
</head>
<body>
	<script>
		// js对象数组(JSON) 根据某个共同字段 分组
		/**
		 * [
			    {"id":"1001","name":"值1","value":"111"},
			    {"id":"1001","name":"值1","value":"11111"},
			    {"id":"1002","name":"值2","value":"25462"},
			    {"id":"1002","name":"值2","value":"23131"},
			    {"id":"1002","name":"值2","value":"2315432"},
			    {"id":"1003","name":"值3","value":"333333"}
			]
		 */
		/**
		 * [
			    {
			        "id": "1001",
			        "name": "值1",
			        "data": [
			            {"id": "1001", "name": "值1", "value": "111"},
			            { "id": "1001", "name": "值1", "value": "11111"}
			        ]
			    },
			    {
			        "id": "1002",
			        "name": "值2",
			        "data": [
			            { "id": "1002",  "name": "值2", "value": "25462" },
			            { "id": "1002", "name": "值2", "value": "23131"},
			            {"id": "1002", "name": "值2","value": "2315432" }
			        ]
			    },
			    {
			        "id": "1003",
			        "name": "值3",
			        "data": [
			            {"id": "1003", "name": "值3", "value": "333333" }
			        ]
			    }
			]
		 */
		var arr = [
		    {"id":"1001","name":"值1","value":"111"},
		    {"id":"1001","name":"值1","value":"11111"},
		    {"id":"1002","name":"值2","value":"25462"},
		    {"id":"1002","name":"值2","value":"23131"},
		    {"id":"1002","name":"值2","value":"2315432"},
		    {"id":"1003","name":"值3","value":"333333"}
		];

		var map = {},
		    dest = [];
		for(var i = 0; i < arr.length; i++){
		    var ai = arr[i];
		    if(!map[ai.id]){
		        dest.push({
		            id: ai.id,
		            name: ai.name,
		            data: [ai]
		        });
		        map[ai.id] = ai;
		        console.log('map',map)
		        console.log('dest',dest)
		        /**
		         * map 
						{1001: {…}}
						1001: {id: "1001", name: "值1", value: "111"}
						1002: {id: "1002", name: "值2", value: "25462"}
						1003: {id: "1003", name: "值3", value: "333333"}
						__proto__: Object
				   dest 
						(3) [{…}, {…}, {…}]
						0: {id: "1001", name: "值1", data: Array(2)}
						1: {id: "1002", name: "值2", data: Array(3)}
						2: {id: "1003", name: "值3", data: Array(1)}
						length: 3
						__proto__: Array(0)
		         */
		    }else{
		        for(var j = 0; j < dest.length; j++){
		            var dj = dest[j];
		            if(dj.id == ai.id){
		                dj.data.push(ai);
		                break;
		            }
		        }
		    }
		}

		console.log(dest);
	</script>
</body>
</html>